<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
 ?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl('/addons/swfuploaders/css/default.css');?>" media="all" />

<script type="text/javascript">
    var uploadAllFiles, uploadOnlyImageFiles;

    window.onload = function() {
        uploadAllFiles = new SWFUpload({
            // Backend Settings
            upload_url: "<?php echo $this->baseurl('/common/general_upload/'); ?>",
            post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},

            // File Upload Settings
            file_size_limit : "102400",	// 100MB
            file_types : "*.*",
            file_types_description : "All Files",
            file_upload_limit : "100",
            file_queue_limit : "0",

            // Event Handler Settings (all my handlers are in the Handler.js file)
            file_dialog_start_handler : fileDialogStart,
            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,
            // Button Settings
            button_image_url : "<?php echo $this->baseurl('/addons/swfuploaders/XPButtonUploadText_61x22.png'); ?>",
            button_placeholder_id : "spanButtonPlaceholder1",
            button_width: 61,
            button_height: 22,

            // Flash Settings
            flash_url : "<?php echo $this->baseurl('/addons/swfuploaders/swfupload/swfupload.swf'); ?>",

            custom_settings : {
                progressTarget : "fsUploadProgress1",
                cancelButtonId : "btnCancel1"
            },

            // Debug Settings
            debug: false
        });

        uploadOnlyImageFiles = new SWFUpload({
            // Backend Settings
            upload_url: "<?php echo $this->baseurl('/common/general_upload/'); ?>",
            post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"},

            // File Upload Settings
            file_size_limit : "102400",	// 100MB
            file_types : "*.jpg;*.gif;*.png",
            file_types_description : "Image Files",
            file_upload_limit : "100",
            file_queue_limit : "100",

            // Event Handler Settings (all my handlers are in the Handler.js file)
            file_dialog_start_handler : fileDialogStart,
            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,

            // Button Settings
            button_image_url : "<?php echo $this->baseurl('/addons/swfuploaders/XPButtonUploadText_61x22.png'); ?>",
            button_placeholder_id : "spanButtonPlaceholder2",
            button_width: 61,
            button_height: 22,

            // Flash Settings
            flash_url : "<?php echo $this->baseurl('/addons/swfuploaders/swfupload/swfupload.swf'); ?>",

            swfupload_element_id : "flashUI2",		// Setting from graceful degradation plugin
            degraded_element_id : "degradedUI2",	// Setting from graceful degradation plugin

            custom_settings : {
                progressTarget : "fsUploadProgress2",
                cancelButtonId : "btnCancel2"
            },

            // Debug Settings
            debug: false
        });
     }

    window.addEvent("domready", function() {
        $$(".upload").addEvent("click", function(e){
            if( $("hidden_content").getStyle("display") == 'none')
            {
                $("hidden_content").setStyle("display", "block");
            }
            else
            {

                $("hidden_content").setStyle("display", "none");
            }
        });
    });
</script>
<div style="background-color:#D9E5EE">
    <div class="displaynone" id="hidden_content">
        <table border="0" align="center" width="100%">
            <tr>
                <td align="center">
                    <div class="app_box">
                        <h3 class="app_box_title">All file format allowed</h3>
                        <div class="box-body innter">
                            <p>
                                <div class="fieldset flash" id="fsUploadProgress1"></div>
                                <span id="spanButtonPlaceholder1"></span>
                                <input id="btnCancel1" type="button" value="Cancel Uploads" onclick="cancelQueue(uploadAllFiles);" disabled="disabled" class="simple_button" />
                                 <?php echo App::Load("Helper/Html")->linkTag($this->baseurl("/admin/filemanager"),"Refresh"); ?>
                            </p>
                        </div>
                     </div>
                </td>
                <td align="center">
                    <div class="app_box">
                        <h3 class="app_box_title">Only Image files are allowed</h3>
                        <div class="box-body innter">
                                <div class="fieldset flash" id="fsUploadProgress2"></div>
                                <span id="spanButtonPlaceholder2"></span>
                                <input id="btnCancel2" type="button" value="Cancel Uploads" onclick="cancelQueue(uploadOnlyImageFiles);" disabled="disabled" class="simple_button" />
                                <?php echo App::Load("Helper/Html")->linkTag($this->baseurl("/admin/filemanager"),"Refresh"); ?>
                        </div>
                     </div>
                </td>
            </tr>
        </table>

    </div>
<?php App::Helper('Toolbar')->setTitle($this->__("File Manager"))->setBtnCustomHTML(App::load("Helper/Html")->buttonTag("Button[Toggle]","Upload",array("class"=>"upload")))->setBtnBack()->Render(array('code'=>'filemanager_top')); ?>

<form method="post" style="margin:5px 10px">
	<input type="text" class="sys-conf-input"  style="padding:4px" name="data[FileManager][search]" value="<?php echo $srcstr;?>" />
	<input type="submit" class="sys-conf-input" style="cursor:pointer" value="Search" />
</form>
<?php
    if( !empty($file_list['data']))
    {
        foreach( $file_list['data'] as $key => $val )
        {
            $file_path = $this->get_config("filemanager_path") . "/{$val['name']}";

            if( App::Load("Helper/Utility")->is_image( $val['name'] ))
            {
                $img_path = $this->get_config("filemanager_path") . "/{$val['name']}";
            }
            else
            {
                $img_path = $this->basedir("/images/admin/file.gif");
            }

            if( App::Load("Helper/Utility")->is_image( $val['name'] ))
            {
                $optimizepath = App::Load("Helper/Html")->inputTag("file",$this->baseurl('/common/get_image/' . base64_encode( $file_path) . '/50/fix'),array("class"=>"sys-conf-input"));
            }
            else
            {
                $optimizepath = App::Load("Helper/Html")->inputTag("file",$this->baseurl('/common/download/' . base64_encode( $file_path)),array("class"=>"sys-conf-input"));
            }

                App::Module('DataGrid')->addRow(
                    App::Load("Helper/Html")->linkTag($this->baseurl('/common/download/' . base64_encode( $file_path)),App::Load("Helper/Html")->imgDTag($img_path,"/50/fix")),
                    App::Load("Helper/Html")->inputTag("filename",$val['name'],array("class"=>"sys-conf-input")),
                    App::Load("Helper/Html")->inputTag("filepath",$this->baseurl("/{$file_path}"),array("class"=>"sys-conf-input")),
                    $optimizepath,
                    App::Load("Helper/Html")->linkTag($this->baseurl('/admin/filemanager/delete/' . base64_encode( $val['name'])),App::Load("Helper/Html")->imgTag($this->baseurl('/images/admin/remove.gif')))
                );
        }
            App::Module('DataGrid')->setHeader(array('Download','File Name', 'Direct Link', 'Optimized Link','Options'))
                                   ->setFooter($file_list['link'] . " " . $file_list['paging'] . " &nbsp;&nbsp; Total Entry : " . $file_list["total"])
                                   ->Render();
    }
	else
	{
		echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'message', 'message' => 'No fime information found.'));
	}
?>
<?php echo App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'filemanager_bottom'));?>
</div>